package com.bds.btcdc.web.service;

import com.bds.btcdc.web.model.TExchange;
import com.bds.btcdc.web.model.TUser;
import com.bds.btcdc.web.model.TUserRate;
import org.apache.log4j.Logger;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.impl.NutDao;
import org.nutz.dao.sql.Sql;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by DongChenchen on 2018/4/25 0025
 */
@Service
public class UserRateService {
    private Logger LOGGER = Logger.getLogger(getClass());
    @Resource
    private NutDao dao;

    public TUserRate getByUserIdAndcode(Long user_id,String code){
        Sql sql= Sqls.create("select a.* from t_user_rate a where a.code=@code and a.user_id=@user_id");
        sql.setParam("code",code);
        sql.setParam("user_id",user_id);
        sql.setEntity(dao.getEntity(TUserRate.class));
        sql.setCallback(Sqls.callback.entity());
        dao.execute(sql);
        return sql.getObject(TUserRate.class);
    }
    public Boolean update(TUserRate ur){
        if(ur.getId()==null){
            return dao.insert(ur)==null?false:true;
        }else {
            return dao.update(ur) == 1 ? true : false;
        }
    }
    public Boolean delete(TUserRate ur){
        return dao.delete(ur)==1?true:false;
    }
    public Boolean deleteByCode(String code){
        Sql sql= Sqls.create("delete from t_user_rate a where a.code=@code");
        sql.setParam("code",code);
        try {
            dao.execute(sql);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }


    public void test(){
        dao.create(TUserRate.class,false);
    }


}
